package com.hamster.crmpre.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hamster.crmpre.mapper.*;
import com.hamster.crmpre.pojo.*;
import com.hamster.crmpre.service.MessageViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ：Lizhipeng
 * @date ：Created in 2019/12/27 11:30
 * @description：消息列表中消息详细视图的实现类
 * @modified By：
 * @version: 1.0
 */
@Service
public class MessageViewServiceImpl implements MessageViewService {

    @Autowired
    private HandOverAssistantMapper handOverAssistantMapper;
    @Autowired
    private MessageBuyVerifyMapper messageBuyVerifyMapper;
    @Autowired
    private HandOverCustomerAssetsMapper handOverCustomerAssetsMapper;
    @Autowired
    private NoticeMapper noticeMapper;
    @Autowired
    private MessageAllianceMapper messageAllianceMapper;
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private CustomerMapper customerMapper;
    /**
     * 根据messageLink去查询转交助教的具体视图信息
     * @param messageLink 个人消息对应的是哪条转交助教消息
     * @return 一条助教消息
     */
    @Override
    public HandOverAssistant getHandOverAssistant(String messageLink) {
        QueryWrapper<HandOverAssistant> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", messageLink);
        HandOverAssistant handOverAssistant = handOverAssistantMapper.selectOne(queryWrapper);
        Employee employee = employeeMapper.selectById(handOverAssistant.getSender());
        Customer customer = customerMapper.selectById(handOverAssistant.getCustomerId());
        handOverAssistant.setSenderName(employee.getName());//消息发送者姓名
        handOverAssistant.setCustomerPhone(customer.getPhone());//客户手机号
        handOverAssistant.setProject(customer.getProjectTitle());//购买项目
        handOverAssistant.setCustomerRegion(customer.getRegion());//所在地区
        handOverAssistant.setCustomerPosition(customer.getPosition());//客户职位

        return handOverAssistant;
    }
    /**
     * 根据messageLink去查询购买审核的具体视图信息
     * @param messageLink 个人消息对应的是哪条购买审核消息
     * @return 一条购买审核消息
     */
    @Override
    public MessageBuyVerify getMessageBuyVerify(String messageLink) {
        QueryWrapper<MessageBuyVerify> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", messageLink);
        return messageBuyVerifyMapper.selectOne(queryWrapper);
    }

    /**
     * 根据messageLink去查询转交客户资产的具体视图信息
     * @param messageLink 个人消息对应的是哪条转交客户资产
     * @return 一条转交客户资产信息
     */
    @Override
    public HandOverCustomerAssets getHandOverCustomerAssets(String messageLink) {
        QueryWrapper<HandOverCustomerAssets> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", messageLink);
        HandOverCustomerAssets handOverCustomerAssets =  handOverCustomerAssetsMapper.selectByMessageLinkId(messageLink);
        return handOverCustomerAssets;
    }

    @Override
    public Notice getNotice(String messageLink) {
        return noticeMapper.selectById(messageLink);
    }

    /**
     * 获取项目加盟消息详情
     * @param messageLink
     * @return
     */
    @Override
    public MessageAlliance getMessageAlliance(String messageLink) {
        QueryWrapper<MessageAlliance> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", messageLink);
        MessageAlliance messageAlliance = messageAllianceMapper.selectOne(queryWrapper);
        return messageAlliance;
    }
}
